package com.qianniu.napi.admin.service.akka;

import akka.actor.UntypedActor;
import com.qianniu.napi.admin.entity.wxbean.WxmappTemplate;
import com.qianniu.napi.admin.service.IRedisService;
import com.qianniu.napi.common.util.ObjectUtil;
import com.qianniu.napi.common.util.SpringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WxtemplateActor extends UntypedActor {

    private final static Logger logger = LoggerFactory.getLogger(WxtemplateActor.class);
    private IRedisService redisService = (IRedisService) SpringUtil.getBean("redisServiceImpl");

    @Override
    public void onReceive(Object message) {
        logger.info("---------------------------------------------------WxtemplateActor in");

        if (message instanceof String) {
            String msg = message.toString();
            logger.info(">>>>>>WxtemplateActor receive message:" + msg);
            // 格式 type+uid+toke
            String[] arr = msg.split("@");
            logger.info(">>>>>>receive arr.length=" + arr.length);
//            if (arr.length < 3) return;

            String mpid = arr[0];
            String formid = arr[1];
            try {
                WxmappTemplate wxtpl = redisService.get(formid);
//                ObjectUtil.sendTemplateMsg(redisService.getWxtoken(mpid), wxtpl);
                redisService.del(formid);
            } catch (Exception e) {
                logger.error(">>>>>>WxtemplateActor process error", e);

            }
        }
    }

}
